<?php
/**
 * session类
 * $_SESSION 封装;以后亦可以根据其他实现方式修改
 */
class session {

	private static $_instance = null;

	/**
	 * 获取实体
	 */
	public static function getInstance()
	{
		if (null === self::$_instance)
		{
			self::$_instance = new self();
		}
		return self::$_instance;
	}

	/**
	 * 设置值
	 * @method set
	 * @param  [type] $name  [description]
	 * @param  [type] $value [description]
	 * @author NewFuture
	 */
	public static function set($name, $value)
	{
		if (null === self::$_instance)
		{
			self::$_instance = new self();
		}
		$_SESSION[$name] = $value;
	}

	/**
	 * 获取值
	 * @method get
	 * @param  [type] $name [description]
	 * @return [type]       [description]
	 * @author NewFuture
	 */
	public static function get($name)
	{
		$instance = self::getInstance();
		if (isset($_SESSION[$name]))
		{
			return $_SESSION[$name];
		}
		else
		{
			return null;
		}
	}

	/**
	 * 删除变量
	 * @method del
	 * @param  [type] $name [description]
	 * @return [type]       [description]
	 * @author NewFuture
	 */
	public static function del($name)
	{
		$instance = self::getInstance();
		unset($_SESSION[$name]);
	}

	/**
	 * 清楚
	 * @method clear
	 * @return [type] [description]
	 * @author NewFuture
	 */
	public static function clear()
	{
		$instance = self::getInstance();
		usset($_SESSION);
		session_destroy();
	}

	private function __construct()
	{
		session_start();
	}

}